package com.sx.pipeline.adapter

import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.view.BLTextView
import com.sx.pipeline.R
import com.sx.pipeline.app.config.IntentKey
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.repos.http.res.ReleaseNeedsVO
import com.sx.pipeline.utils.CountDownUtil

/**
 * @Author：YY
 * @Date：2022/2/10
 * @Describe: 参与供应列表适配器
 */
class SupplierNeedsListAdapter(
    dataList: MutableList<ReleaseNeedsVO>
) : BaseQuickAdapter<ReleaseNeedsVO, BaseViewHolder>(
    R.layout.item_supplier_needs_list, dataList
) {
    private var countDownUtil: CountDownUtil? = null

    override fun convert(holder: BaseViewHolder, item: ReleaseNeedsVO) {
        //标题2
        holder.setText(R.id.tv_title, item.title)
        //需要数量
        holder.setText(R.id.tv_need_num, "需要数量：${item.omsNeedServe?.quantity+item.omsNeedServe?.unit}")
        //供应时间
        holder.setText(R.id.tv_need_time, "供应时间：${item.omsNeedServe?.startDate}-${item.omsNeedServe?.endDate}")
        //供应服务区域
        holder.setText(R.id.tv_provide_area, "需求服务地点：${item.addressDetail}")

        //供应负责人
        holder.setText(R.id.tv_provide_principal, "供应负责人：${item.contact}")
        if (item.orderQuotedPrice==null){
            //联系方式
            holder.setText(R.id.tv_provide_contact, "联系方式：**** **** ****")
        }else{
            //联系方式
            holder.setText(R.id.tv_provide_contact, "联系方式：${item.contactPhone}")
        }


        if (item.needQuotePrice.toInt()==0){
            holder.setGone(R.id.tv_provide_money,true)
        }else{
            holder.setVisible(R.id.tv_provide_money,true)
            holder.setText(R.id.tv_provide_money,""+item.needQuotePrice)
        }
        //查看需求
        holder.getView<BLTextView>(R.id.tv_consult).setOnClickListener {
            ARouter.getInstance().build(RoutePath.Mine.SUPPLIER_NEEDS_DETAIL).withInt(IntentKey.ID,item.id).navigation()
        }
       holder.setText(R.id.tv_finish_time, item.createTime)
    }

    fun destoryTimer(){
        if (countDownUtil!=null){
            countDownUtil?.onDestroy()
        }
    }

}